package com.gomore.opple.module.orderpay.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gomore.opple.R;
import com.gomore.opple.model.OrderPromotionModel;

import java.util.List;

/**
 * Created by asus on 2017/6/9.
 */
public class OrderPromotionAdapter extends BaseAdapter {
    Context mContext;
    List<OrderPromotionModel> morderPromotionModelList;

    public OrderPromotionAdapter(Context context, List<OrderPromotionModel> orderPromotionModelList) {
        mContext = context;
        morderPromotionModelList = orderPromotionModelList;
    }

    @Override
    public int getCount() {
        return morderPromotionModelList.size();
    }

    @Override
    public Object getItem(int position) {
        return morderPromotionModelList == null ? 0 : morderPromotionModelList.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_promotion_item, parent, false);
            viewHolder.title = (TextView) convertView.findViewById(R.id.title);
            viewHolder.content = (TextView) convertView.findViewById(R.id.content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        OrderPromotionModel orderPromotionModel = morderPromotionModelList.get(position);
        if (orderPromotionModel.getTitle() != null) {
            viewHolder.title.setText(orderPromotionModel.getTitle());
        }
        if (orderPromotionModel.getContent() != null) {
            viewHolder.content.setText(orderPromotionModel.getContent());
        }
        return convertView;
    }

    class ViewHolder {
        TextView title, content;
    }
}
